home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-13 / mewin10s.zip / MSWDRV.C < prev    next >
C/C++ Source or Header  |  1992-02-20  |  21KB  |  637 lines

  1. /* The routines in this file provide drivers for display and input under
  2.    the Microsoft Windows environment on an IBM-PC or compatible
  3.    computer.
  4.  
  5.    Must be compiled with Borland C++ 2.0.
  6.  
  7.    It should not be compiled if the WINDOW_MSWIN symbol is not set */
  8.  
  9. #define termdef 1           /* don't define term external */
  10.  
  11. #include    "estruct.h"
  12. #include    "elang.h"
  13. #include    <stdio.h>
  14. #include    <time.h>
  15. #include    "eproto.h"
  16. #include    "edef.h"
  17.  
  18. #include    "mswin.h"
  19.  
  20. #define     NPAUSE  1000    /* pause for fence-showing, 1 second */
  21. #define     MARGIN  8       /* size of minimal margin and */
  22. #define     SCRSIZ  20      /* scroll size for extended lines */
  23.  
  24. /* terminal interface table entries */
  25. /* Note that these are not prototyped as PASCAL NEAR like they are in
  26.    estruct.h. In estruct.h, NEAR preprocesses as spaces.
  27.    Due to windows.h, this module cannot use "PASCAL NEAR" that way */
  28. static int   PASCAL mswnop();
  29. static int   PASCAL mswopen();
  30. static int   PASCAL mswgetc();
  31. static int   PASCAL mswputc();
  32. static int   PASCAL mswflush();
  33. static int   PASCAL mswbeep();
  34. static int   PASCAL mswmove();
  35. static int   PASCAL msweeol();
  36. static int   PASCAL msweeop();
  37. static int   PASCAL mswbeep();
  38. static int   PASCAL mswrev();
  39. static int   PASCAL mswrez();
  40. #if COLOR
  41. static int   PASCAL mswsetfor();
  42. static int   PASCAL mswsetback();
  43. #endif
  44. static int   PASCAL mswsleep();
  45. static int   PASCAL mswnewscr();
  46. static int   PASCAL mswdelscr();
  47. static int   PASCAL mswselscr();
  48. static int   PASCAL mswsizscr();
  49. static int   PASCAL mswtopscr();
  50.  
  51. /* Standard terminal interface dispatch table.
  52. */
  53. NOSHARE TERM term    = {
  54.         HUGE,
  55.         HUGE,
  56.         HUGE,
  57.         HUGE,
  58.         0,
  59.         0,
  60.     MARGIN,
  61.     SCRSIZ,
  62.     NPAUSE,
  63.         mswopen,    /* t_open: Open terminal at the start */
  64.         mswnop,     /* t_close: Close terminal at end */
  65.     mswnop,     /* t_kopen: Open keyboard */
  66.     mswnop,     /* t_kclose: close keyboard */
  67.     mswgetc,    /* t_getchar: Get character from keyboard */
  68.         mswputc,    /* t_putchar: Put character to display */
  69.         mswflush,   /* t_flush: Flush output buffers */
  70.         mswmove,    /* t_move: Move the cursor, origin 0 */
  71.         msweeol,    /* t_eeol: Erase to end of line */
  72.         msweeop,    /* t_eeop: Erase to end of page */
  73.     mswnop,     /* t_clrdesk: Clear the page totally */
  74.     mswbeep,    /* t_beep: Sound beep */
  75.     mswrev,     /* t_rev: set reverse video state */
  76.     mswrez,     /* t_rez: change screen resolution */
  77. #if    COLOR
  78.     mswsetfor,  /* t_setfor: set forground color */
  79.     mswsetback, /* t_setback: set background color */
  80. #endif
  81.     mswsleep,   /* t_sleep: wait a while */
  82.     mswnewscr,  /* t_newscr: create new "screen" display */
  83.     mswdelscr,  /* t_delscr: destroy "screen" display */
  84.     mswselscr,  /* t_selscr: select "screen" display for IO */
  85.     mswsizscr,  /* t_sizscr: resize "screen" display */
  86.         mswtopscr   /* t_topscr: bring "screen" to top */
  87. };
  88.  
  89. #define MAXMLHIST   8       /* must be a power of 2 */
  90. #define MLHISTMASK  0x7     /* corresponding bit mask */
  91. static char *MLHistory[MAXMLHIST] = {NULL};
  92.     /* circular history of the last few message line entries */
  93. static int  MLHistOld = 0;  /* index of the oldest message */
  94. static int  MLHistNew = 0;  /* index of the first empty slot */
  95.  
  96. static HWND hIOWnd;         /* current window where I/Os take place */
  97.  
  98. static int  UpdateRow;      /* Row being updated (-1 for no update) */
  99.  
  100. static struct {
  101.     int leftmost;
  102.     int rightmost;      /* -1 indicates the range is empty */
  103. } UpdateCol;                /* Columns to invalidate on UpdateRow */
  104.  
  105. static SCREEN *IOScr;       /* Screen affected by the I/Os */
  106.  
  107. static BOOL RevStatus;      /* Reverse video flag */
  108. #if     COLOR
  109. static int  ForgColor;      /* current selection of foreground and */
  110. static int  BackColor;      /* background colors */
  111. #endif
  112.  
  113. /* PushMLHist:  store the last message line contents in the history */
  114. /* ==========                                                       */
  115.  
  116. static void PASCAL  PushMLHist (void)
  117. {
  118.     char    *ml;
  119.     int     i, e;
  120.  
  121.     for (e = MLSIZE - 1; e >= 0; e--) if (MLBuf[e] != ' ') break;
  122.         /* e = index of the last non-space char */
  123.     if (e < 0) return;
  124.     if ((ml = MLHistory[MLHistNew] = malloc (e + 2)) != NULL) {
  125.         for (i = 0; i <= e; i++) *ml++ = MLBuf[i];
  126.         *ml = '\0';     /* terminate the string */
  127.     MLHistNew = (MLHistNew + 1) & MLHISTMASK;
  128.     if (MLHistOld == MLHistNew) {
  129.         /* the history is full. This old entry needs to be discarded */
  130.         free (MLHistory[MLHistOld]);
  131.         MLHistOld = (MLHistOld + 1) & MLHISTMASK;
  132.     }
  133.     }
  134. } /* PushMLHist */
  135.  
  136. /* MLHistDlgProc:   dialog proc for the Message Line History */
  137. /* =============                                             */
  138.  
  139. int EXPORT far pascal  MLHistDlgProc (HWND hDlg, WORD wMsg,
  140.                                       WORD wParam, DWORD lParam)
  141. {
  142.     switch (wMsg) {
  143.         
  144.     case WM_INITDIALOG:
  145.         {
  146.             char    s[50];
  147.  
  148.             strcpy (s, PROGNAME);
  149.             strcat (s, TEXT330);
  150.             SetWindowText (hDlg, s);
  151.         }
  152.         /*-fill the list box */
  153.         while (MLHistOld != MLHistNew) {
  154.             SendDlgItemMessage (hDlg, ID_HIST, LB_ADDSTRING, 0,
  155.                                 (DWORD)MLHistory[MLHistOld]);
  156.             free (MLHistory[MLHistOld]);
  157.             MLHistOld = (MLHistOld + 1) & MLHISTMASK;
  158.         }
  159.     /*-scroll the last message into view */
  160.         {
  161.             int     i;
  162.  
  163.             i = SendDlgItemMessage (hDlg, ID_HIST, LB_GETCOUNT, 0, 0L);
  164.             SendDlgItemMessage (hDlg, ID_HIST, LB_SETCURSEL, i - 1, 0L);
  165.             SendDlgItemMessage (hDlg, ID_HIST, LB_SETCURSEL, -1, 0L);
  166.         }
  167.     return TRUE;
  168.     
  169.     case WM_COMMAND:
  170.     if (HIWORD(lParam) != BN_CLICKED) break;
  171.     if (wParam == 1) {
  172.         EndDialog (hDlg, 0);
  173.         return TRUE;
  174.     }
  175.     break;
  176.     }
  177.     return FALSE;
  178. } /* MLHistDlgProc */
  179.  
  180. /* mlhistory:   displays the message line history box */
  181. /* =========                                          */
  182.  
  183. /* This function is needed because the message line only shows the last
  184.    message. If a macro fails, it usually generates a slew of errors
  185.    (each beginning by a \n). Eventually, calling this function in the
  186.    core editor loop will pop up a dialog box showing up to MAXMLHIST-1
  187.    past messages */
  188.  
  189. PASCAL mlhistory (void)
  190. {
  191.     FARPROC     ProcInstance;
  192.  
  193.     PushMLHist ();
  194.     mlferase ();
  195.     ProcInstance = MakeProcInstance ((FARPROC)MLHistDlgProc,
  196.                          hEmacsInstance);
  197.     DialogBox (hEmacsInstance, "MLHIST", hFrameWnd, ProcInstance);
  198.     FreeProcInstance (ProcInstance);
  199. } /* mlhistory */
  200.  
  201. /*****************************************/
  202. /* mswopen: initialize windows interface */
  203. /* =======                               */
  204.  
  205. static int PASCAL mswopen ()
  206. {
  207.     static BOOL FirstTime = TRUE;
  208.  
  209.     if (FirstTime) {
  210.     int     x;
  211.  
  212.     revexist = TRUE;
  213.     eolexist = TRUE;
  214.     strcpy (sres, "MSWIN");     /* $SRES emacs variable */
  215.     MLBuf = (char*)malloc(MLSIZE);
  216.     for (x = 0; x < MLSIZE;) MLBuf[x++] = ' ';
  217.     FirstTime = FALSE;
  218.     }
  219.     UpdateRow = -1;
  220.     UpdateCol.rightmost = -1;
  221.     UpdateCol.leftmost = HUGE; /* empty range */
  222.     return 0;
  223. } /* mswopen */
  224.  
  225. /***************************************************/
  226. /* mswgetc: get character from keyboard (or mouse) */
  227. /* =======                                         */
  228.  
  229. static int PASCAL mswgetc ()
  230. {
  231.     return GetInput ();
  232. } /* mswgetc */
  233.  
  234. /*************************************/
  235. /* mswputc: put character to display */
  236. /* =======                           */
  237.  
  238. static int PASCAL mswputc (c)
  239. int     c;  /* character to write (or 0 for dummy write) */
  240. {
  241.     /*-Set UpdateRow to CurrentRow, invalidating the changed cells in the
  242.        previous update row */
  243.     if (UpdateRow != CurrentRow) {
  244.     if ((UpdateCol.rightmost >= 0) && (UpdateRow >= 0)) {
  245.             InvalidateCells (hIOWnd, UpdateCol.leftmost, UpdateRow,
  246.                              UpdateCol.rightmost, UpdateRow);
  247.     }
  248.     UpdateRow = CurrentRow;
  249.     UpdateCol.rightmost = -1;
  250.     UpdateCol.leftmost = HUGE; /* empty range */
  251.     }
  252.  
  253.     /*-set the colors and reverse status in the display buffer */
  254.     if (hIOWnd != hFrameWnd) {  /* not supported on message line */
  255.     register VIDEO   *vp;
  256.  
  257.     vp = IOScr->s_physical[UpdateRow];
  258.     vp->v_fcolor = ForgColor;
  259.     vp->v_bcolor = BackColor;
  260.     if (RevStatus) vp->v_flag |= VFREV;
  261.     else vp->v_flag &= ~VFREV;
  262.     }
  263.     
  264.     /*-update the cursor's position and the UpdateCol range. Update the
  265.        message line buffer if that's where the fun is */
  266.     if (c != 0) {
  267.     if (CurrentCol < UpdateCol.leftmost) UpdateCol.leftmost = CurrentCol;
  268.     if (CurrentCol > UpdateCol.rightmost) UpdateCol.rightmost = CurrentCol;
  269.     if (hIOWnd == hFrameWnd) {          /* message line */
  270.         if (c == '\b') {
  271.             if (CurrentCol > 0) MLBuf[--CurrentCol] = ' ';
  272.         }
  273.         else {
  274.             if (c == '\n') PushMLHist();
  275.             else {
  276.             MLBuf[CurrentCol] = c;
  277.             if (CurrentCol < MLSIZE - 1) ++CurrentCol;
  278.         }
  279.         } 
  280.     }
  281.     else ++CurrentCol;
  282.     }
  283.     return 0;
  284. } /* mswputc */
  285.  
  286. /**************************************************/
  287. /* mswflush:    update display from output buffer */
  288. /* ========                                       */
  289.  
  290. static int PASCAL mswflush ()
  291. {
  292.     if ((UpdateCol.rightmost >= 0) && (UpdateRow >= 0)) {
  293.     InvalidateCells (hIOWnd, UpdateCol.leftmost, UpdateRow,
  294.                          UpdateCol.rightmost, UpdateRow);
  295.     }
  296.     UpdateRow = -1;
  297.     if (!InternalRequest && (hIOWnd == hFrameWnd)) UpdateWindow (hIOWnd);
  298.     /* note: we do not update screens in real time */
  299.     MoveEmacsCaret (hIOWnd, CurrentCol, CurrentRow);
  300.         /* some caret movement is directly handled by the driver (see
  301.        mswputc) */
  302.     return 0;
  303. } /* mswflush */
  304.  
  305. /****************************/
  306. /* mswmove: move the cursor */
  307. /* =======                  */
  308.  
  309. static int PASCAL mswmove (int newrow, int newcol)
  310. {
  311.     CurrentCol = newcol;
  312.  
  313.     /*-perform IO windows switching depending on the addressed row: if
  314.        beyond the IO screen, the message line is addressed*/
  315.     if (!IOScr || (newrow >= IOScr->s_nrow)) {
  316.         hIOWnd = hFrameWnd;
  317.         CurrentRow = 0;
  318.     }
  319.     else {
  320.         hIOWnd = IOScr->s_drvhandle;
  321.         CurrentRow = newrow;
  322.     }
  323.  
  324.     /*-update the caret */
  325.     MoveEmacsCaret (hIOWnd, CurrentCol, CurrentRow);
  326.     return 0;
  327. } /* mswmove */
  328.  
  329. /*********************************/
  330. /* msweeol: erase to end of line */
  331. /* =======                       */
  332.  
  333. static int PASCAL msweeol ()
  334. {
  335.     mswputc (0);    /* ensure change of row is properly handled */
  336.     UpdateCol.leftmost = min(UpdateCol.leftmost,CurrentCol);
  337.     if (hIOWnd == hFrameWnd) {          /* message line */
  338.     int     x;
  339.     
  340.     for (x = CurrentCol; x < MLSIZE;) MLBuf[x++] = ' ';
  341.     UpdateCol.rightmost = MLSIZE - 1;
  342.     }
  343.     else {
  344.     UpdateCol.rightmost = IOScr->s_ncol;
  345.     }
  346.     mswflush ();
  347.     return 0;
  348. } /* msweeol */
  349.  
  350. /*********************************/
  351. /* msweeop: erase to end of page */
  352. /* =======                       */
  353.  
  354. static int PASCAL msweeop ()
  355. {
  356.     if (hIOWnd == hFrameWnd) {          /* message line */
  357.     msweeol ();     /* only one line here */
  358.     return 0;
  359.     }
  360.     mswputc (0);    /* ensure change of row is properly handled */
  361.     UpdateCol.leftmost = min(UpdateCol.leftmost,CurrentCol);
  362.     InvalidateCells (hIOWnd, UpdateCol.leftmost, UpdateRow,
  363.              IOScr->s_ncol, UpdateRow);
  364.     if (CurrentRow + 1 < IOScr->s_nrow) {
  365.     register int    r;
  366.     register VIDEO  *vp;
  367.  
  368.     /*-propagate the colors and reverse status */
  369.     for (r = CurrentRow + 1; r < IOScr->s_nrow; r++) {
  370.         vp = IOScr->s_physical[r];
  371.         vp->v_fcolor = ForgColor;
  372.         vp->v_bcolor = BackColor;
  373.         if (RevStatus) vp->v_flag |= VFREV;
  374.         else vp->v_flag &= ~VFREV;
  375.     }
  376.     /*-flag the area for repaint */
  377.     InvalidateCells (hIOWnd, 0, CurrentRow + 1,
  378.              IOScr->s_ncol, IOScr->s_nrow);
  379.     }
  380.     mswflush ();
  381.     return 0;
  382. } /* msweeop */
  383.  
  384. /*************************/
  385. /* mswbeep: sound a beep */
  386. /* =======               */
  387.  
  388. static int PASCAL mswbeep ()
  389. {
  390.     MessageBeep (0);
  391.     return 0;
  392. } /* mswbeep */
  393.  
  394. /************************************/
  395. /* mswrev:  set reverse video state */
  396. /* ======                           */
  397.  
  398. static int PASCAL mswrev (state)
  399. int     state;      /* TRUE = reverse, FALSE = normal */
  400. {
  401.     RevStatus = state;
  402.     return 0;
  403. } /* mswrev */
  404.  
  405. /************************************/
  406. /* mswrez:  change "resolution"     */
  407. /* ======                           */
  408.  
  409. static int PASCAL mswrez (res)
  410. char    *res;
  411. {
  412.     return TRUE;   /* $SRES is read-only in MSWIN, but returning and
  413.               error may break existing macros */
  414. } /* mswrez */
  415.  
  416. #if COLOR
  417. /* mswsetfor:   set foreground color */
  418. /* =========                         */
  419.  
  420. static int  PASCAL mswsetfor (color)
  421. int     color;
  422. {
  423.     ForgColor = color;
  424.     return 0;
  425. } /* mswsetfor */
  426.  
  427. /* mswsetback:  set background color */
  428. /* ==========                        */
  429.  
  430. static int  PASCAL mswsetback (color)
  431. int     color;
  432. {
  433.     BackColor = color;
  434.     return 0;
  435. } /* mswsetback */
  436. #endif
  437.  
  438. /* mswsleep:    wait a specified time (in ms) in an unobtrusive way */
  439. /* ========                                                         */
  440.  
  441. static int PASCAL   mswsleep (int t)
  442. {
  443.     return TakeANap (t);
  444. } /* mswsleep */
  445.  
  446. /* mswnewscr:   create new MDI window for new screen */
  447. /* =========                                         */
  448.  
  449. static int PASCAL mswnewscr (SCREEN *sp)
  450. /* called by screen.c after the screen structure has been allocated. The
  451.    size of the screen will be determined by the window's size. returns
  452.    TRUE if successful. */
  453. {
  454.     MDICREATESTRUCT cs;
  455.     BOOL    Maximized;
  456.  
  457.     if (Maximized = HIWORD(SendMessage (hMDIClientWnd,
  458.                                         WM_MDIGETACTIVE, 0, 0L))) {
  459.         restorescreen (FALSE, 0);   /* de-maximize previous one */
  460.     }
  461.     if (first_screen == NULL) Maximized = TRUE;
  462.     cs.szClass = ScreenClassName;
  463.     cs.szTitle = sp->s_screen_name;
  464.     cs.hOwner = hEmacsInstance;
  465.     cs.x = CW_USEDEFAULT;
  466.     cs.y = CW_USEDEFAULT;
  467.     cs.cx = CW_USEDEFAULT;
  468.     cs.cy = CW_USEDEFAULT;
  469.     if (Maximized) cs.style = WS_MAXIMIZE;
  470.     else cs.style = 0;
  471.     cs.lParam = (DWORD)sp;
  472.     sp->s_virtual = NULL;     /* not NULL will testify of success */
  473.     InternalRequest = TRUE;
  474.     SendMessage (hMDIClientWnd, WM_MDICREATE, 0, (DWORD)(LPSTR)&cs);
  475.     if (sp->s_virtual) {
  476.         if (hFrameWnd == GetActiveWindow ()) SetFocus (sp->s_drvhandle);
  477.     }
  478.     InternalRequest = FALSE;
  479.     if (!sp->s_virtual) {
  480.         mswdelscr (sp);     /* failed, cleanup! */
  481.         return FALSE;
  482.     }
  483.     return TRUE;
  484. } /* mswnewscr */
  485.  
  486. /* mswdelscr:   destroys an MDI window for a disappearing screen */
  487. /* =========                                                     */
  488.  
  489. static int PASCAL mswdelscr (SCREEN *sp)
  490. /* called by screen.c before the screen structure is deallocated */
  491. {
  492.     if (sp->s_drvhandle == hIOWnd) mswflush ();
  493.     if (sp == IOScr) mswselscr (first_screen);
  494.         /* hopefully, at this time, sp!=first_screen */ 
  495.     SendMessage (hMDIClientWnd, WM_MDIDESTROY, sp->s_drvhandle, 0L);
  496. } /* mswdelscr */
  497.  
  498. /* mswselscr:   select a window/screen combination for the next IOs */
  499. /* =========                                                        */
  500.  
  501. static int PASCAL mswselscr (SCREEN *sp)
  502. {
  503.     hIOWnd = sp->s_drvhandle;
  504.     IOScr = sp;
  505. } /* mswselscr */
  506.  
  507. /* mswsizscr:   resize an MDI window to fit the associated screen */
  508. /* =========                                                      */
  509.  
  510. static int PASCAL mswsizscr (SCREEN *sp)
  511. /* called by Emacs when the screen's dimensions have been changed. A resize
  512.    through the MS-Windows interface is handled by the ReSize function in
  513.    mswdisp.c */
  514. {
  515.     HWND    hScrWnd;
  516.     BOOL    Maximized;
  517.     int     RetryCount = -1;    /* prevents infinite loop if frame
  518.                    window can't be resized properly */
  519.  
  520.     if (InternalRequest) return;
  521.     InternalRequest = TRUE;
  522.     hScrWnd = sp->s_drvhandle;
  523.  
  524.     {   /*-If this is iconized, we have to restore it first to be
  525.        allowed to change its size. If it is the active MDI child and
  526.        is maximized, we will actually resize the frame window so, if
  527.        the later is maximized, we restore it first. */
  528.     DWORD   ActiveScr;
  529.  
  530.     ActiveScr = SendMessage (hMDIClientWnd, WM_MDIGETACTIVE, 0, 0L);
  531.     if (IsIconic (hScrWnd)) {
  532.         SendMessage (hMDIClientWnd, WM_MDIRESTORE, hScrWnd, 0L);
  533.     }
  534.         Maximized = (hScrWnd == LOWORD(ActiveScr)) && HIWORD(ActiveScr);
  535.         if (Maximized && IsZoomed (hFrameWnd)) {
  536.             ShowWindow (hFrameWnd, SW_RESTORE);
  537.         }
  538.     }
  539.     do {/*-Now, proceed with resizing... */
  540.     int     Delta;
  541.     RECT    TargetRect, BoundingRect;   /* in MDIClient coordinates */
  542.     RECT    OldClientRect;
  543.     POINT   ClientSize;
  544.  
  545.     GetClientRect (hScrWnd, &OldClientRect);
  546.     MinimumClientSize (hScrWnd, sp->s_ncol, sp->s_nrow,
  547.                            &ClientSize.x, &ClientSize.y);
  548.     if (Maximized) {
  549.         if (((OldClientRect.bottom == ClientSize.y)
  550.              && (OldClientRect.right == ClientSize.x))
  551.                 || (RetryCount > 0)) break; /* exit the resize loop */
  552.         ++RetryCount;
  553.         BoundingRect.left = BoundingRect.top = 0;
  554.         BoundingRect.right = GetSystemMetrics (SM_CXSCREEN);
  555.         BoundingRect.bottom = GetSystemMetrics (SM_CYSCREEN);
  556.         GetWindowRect (hFrameWnd, &TargetRect);
  557.     }
  558.     else {
  559.         GetClientRect (hMDIClientWnd, &BoundingRect);
  560.         GetWindowRect (hScrWnd, &TargetRect);
  561.         ScreenToClient (hMDIClientWnd, (LPPOINT)&TargetRect.right);
  562.         ScreenToClient (hMDIClientWnd, (LPPOINT)&TargetRect.left);
  563.     }
  564.  
  565.         /*-process change of width: we move the right edge. If it would
  566.        go off bounds, we move the left edge back to compensate, but
  567.        never below 0 */
  568.     Delta = ClientSize.x - OldClientRect.right;
  569.     if ((TargetRect.right + Delta) > BoundingRect.right) {
  570.         TargetRect.left += (BoundingRect.right - TargetRect.right)
  571.                                - Delta;
  572.         TargetRect.right = BoundingRect.right;
  573.         if (TargetRect.left < 0) {
  574.         TargetRect.right -= TargetRect.left;
  575.         TargetRect.left = 0;
  576.         }
  577.     }
  578.     else TargetRect.right += Delta;
  579.  
  580.     /*-process change of height: we move the bottom edge. If it
  581.        would go off screen, we move the top edge up to compensate,
  582.        but never beyond 0 */
  583.     Delta = ClientSize.y - OldClientRect.bottom;
  584.     if ((TargetRect.bottom + Delta) > BoundingRect.bottom) {
  585.         TargetRect.top += (BoundingRect.bottom - TargetRect.bottom)
  586.                               - Delta;
  587.         TargetRect.bottom = BoundingRect.bottom;
  588.         if (TargetRect.top < 0) {
  589.         TargetRect.bottom -= TargetRect.top;
  590.         TargetRect.top = 0;
  591.         }
  592.     }
  593.     else TargetRect.bottom += Delta;
  594.  
  595.     SetWindowPos (Maximized ? hFrameWnd : hScrWnd, 0,
  596.                       TargetRect.left, TargetRect.top,
  597.                   TargetRect.right - TargetRect.left,
  598.                   TargetRect.bottom - TargetRect.top,
  599.                       SWP_DRAWFRAME | SWP_NOZORDER);
  600.     } while (Maximized);    /* if Maximized, we loop once in case a
  601.                    change of menu bar height has prevented
  602.                    us from getting the expected client size
  603.                    */
  604.     InternalRequest = FALSE;
  605. } /* mswsizscr */
  606.  
  607. /* mswtopscr:   bring a screen's window to top. */
  608. /* =========                                    */
  609.  
  610. static int PASCAL mswtopscr (SCREEN *sp)
  611.  
  612. /* called by screen.c when selecting a screen for current */
  613. {
  614.     if (!InternalRequest) {
  615.     InternalRequest = TRUE;
  616.     SendMessage (hMDIClientWnd, WM_MDIACTIVATE,
  617.              sp->s_drvhandle, 0L);
  618.         if (HIWORD(SendMessage (hMDIClientWnd, WM_MDIGETACTIVE, 0, 0L))) {
  619.         /* we have a maximized screen. Since we activated it under
  620.            InternalRequest, the new size has not yet been processed
  621.            by emacs, so we have to fix that */
  622.         newwidth (TRUE, DisplayableColumns (sp->s_drvhandle, 0, &EmacsCM));
  623.         newsize (TRUE, DisplayableRows (sp->s_drvhandle, 0, &EmacsCM));
  624.     }
  625.     InternalRequest = FALSE;
  626.     }
  627. } /* mswtopscr */
  628.  
  629. /*************************/
  630. /* mswnop:  No Operation */
  631. /* ======                */
  632.  
  633. static int PASCAL mswnop ()
  634. {
  635.     return 0;
  636. }
  637.